package com.ky.facescan.api.rx.subscriber;

import android.app.Activity;
import android.content.Context;

import com.ky.facescan.api.exception.BaseException;
import com.ky.facescan.api.rx.RxErrorHandler;
import com.ky.facescan.utils.LogUtils;


public abstract class ErrorHandlerSubscriber<T> extends DefaultSubscriber<T> {

    public RxErrorHandler mRxErrorHandler;

    protected Context mContext;
    protected Activity mActivity;

    public ErrorHandlerSubscriber(Context context) {

        this.mContext = context;
        this.mActivity = (Activity) context;

        mRxErrorHandler = new RxErrorHandler(mContext);

    }

    @Override
    public void onError(Throwable e) {
        //打印错误
        BaseException baseException = mRxErrorHandler.handleError(e);

        if (baseException == null) {
            e.printStackTrace();
            LogUtils.e("ErrorHandlerSubscriber   ", e.getMessage());
        } else {
            LogUtils.e("ErrorHandlerSubscriber   ", e.getMessage());
            mRxErrorHandler.showErrorMessage(baseException);
        }
    }


}
